Expand description

🦀 winresult - windows result codes 🦀

Debug-friendly types for windows result codes.

GitHub crates.io docs.rs License

Why?

  • u32 error codes are annoying to dbg!(...). winresult has awesome Debug impls.

  • u32 error codes are annoying to view in your debugger. winresult has awesome *.natvis files. Use natvis-pdbs!

  • typoing ERROR_WHATEVER in a match is a mere warning. ERROR::WHATEVER is a hard error.
    (I’d still use #![deny(unreachable_patterns)] anyways.)

  • ERROR_INVALID_FUNCTION == S_FALSE (== 1.) Lame!

  • ERROR_FILE_NOT_FOUND (2) is a mess. A function or GetLastError might return:

    labelvaluenotes
    ERROR_FILE_NOT_FOUND0x00000002Not an HRESULT (would be “successful”)
    HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND)0x80070002hresult.info “incorrectly” labels ERROR_* as this
    D3D10_ERROR_FILE_NOT_FOUND0x88790002Different facility, same code
    D3D11_ERROR_FILE_NOT_FOUND0x887C0002Different facility, same code
  • ERROR_* is a mixture of HRESULTs and non-HRESULTs. Can you keep them straight? No. No you cannot. Stop lying.

Types

minmaxtypenotes
00xFFFFErrorCode
00x7FFFFFFFHResultSuccess
0x800000000xFFFFFFFFHResultError
00xFFFFFFFFHResultHResultSuccess | HResultError
00xFFF    HResultFacilityMicrosoft
00xFFFFFFFFNtStatusSuccessNtStatus | ErrorNtStatus
00xFFF    NtStatusFacilityMicrosoft
04    NtStatusSeverity
00xFFFFFFFFWaitCodemostly <= 0x102
00xFFFFFFFFErrorHResultOrCodeErrorCode | HResultError

Modules of Note

Buggy Bitwise Comparisons to Forbid

leftrightwhy
ErrorCodeHResultErrornever true, non-overlapping ranges, need to add or remove facility
ErrorCodeHResultSuccessERROR_INVALID_FUNCTION == S_FALSE, need to add or remove facility
ErrorCodeHResultERROR_INVALID_FUNCTION == S_FALSE, need to add or remove facility
ErrorCodeWaitCodeERROR_INVALID_FUNCTION == WAIT_OBJECT_0+1
*Success*Error*never true except by accident

Conversions

Modules

WinRT / UWP AppModel
APPX package
Background Task
Remote Desktop Protocol Bitmap Cache?
Certificates (for e.g. HTTPS etc.)
Certificate Server (for e.g. Certificate Authority validation, etc.)
COM Class
Clipboard
COM
D3DX .X file type errors
OLE / Clipboard Stuff?
Digital Signature
Domain Name Services
OLE / Data Values / Clipboard Stuff?
Display Window Manager (desktop rendering composition)
DirectX
Errors Codes. Typically HResultErrors.
Exchange ActiveSync
Error Codes. Mostly a mixture of HResultErrors and ErrorCodes. submodules: CLOUD_FILE, CLUSTER, DBG, DS, EVT, GRAPHICS, IPSEC, MRM, MUI, NDIS, PRI_MERGE, SECUREBOOT, SERVICE, SVHDX, SXS, SXS::XML, VHD, WMI
Note that ERROR::SUBCATEGORY::CODE is also generally exported as ERROR::SUBCATEGORY_CODE, although the latter is hidden from the docs to reduce clutter.

FACILITY_* Values for HResults and NtStatuses.
pub mod FACILITY::HRESULT::*, FACILITY::NTSTATUS::*;

Full Volume Encryption / Bitlocker
Windows Filtering Platform
“Object Linking and Embedding”
“Object Linking and Embedding”
COM+ registration database
WinRT COM
Success codes
Task Scheduler
[docs.microsoft.com] NtStatus errors, warnings, and other codes (for use in e.g. Kernel / Drivers)
Tablet PC
Trusted Platform Module (1.2)
Trusted Platform Module
Certificate Trust
COM Type Libraries
Universal Telemetry Client (UTC) data in Event Tracing for Windows (ETW) traces.
[docs.microsoft.com] WAIT_* values returned by various WaitFor* and other win32 functions.
Wired Equivalent Privacy
Windows Error Reporting
Windows Hypervisor Platform
Windows Push Notifications?
WinSock

Structs

[docs.microsoft.com] ERROR_* values that aren’t HRESULTs (but might be implicitly convertable)
[docs.microsoft.com] FACILITY_* values corresponding to Microsoft (non-customer) HRSEULTs.
[docs.microsoft.com] FACILITY_* values corresponding to Microsoft (non-customer) NTSTATUSes.
[docs.microsoft.com] WAIT_* values returned by various WaitFor* and other win32 functions.